from django.shortcuts import render
from django.core import serializers
from . import models
from django.http import JsonResponse,HttpResponse
from utils import error
from . import analysis
from . import database

# Create your views here.

# 返回电影数据
def reqMovie(request):
    data = {}
    data['list'] = []
    # 获取2018年电影
    l = models.getMovie2018()
    #
    # # 获取2019年电影
    # l = models.getMovie2019()
    #
    # # 获取2020年电影
    # l = models.getMovie2020()
    #
    # # 获取2021年电影
    # l = models.getMovie2021()
    #
    # # 获取2022年电影
    # l = models.getMovie2022()

    for i in l:
        d = {}
        d.update(i.__dict__)
        d.pop('_state')
        d.pop('id')
        data['list'].append(d)
    
    data['code'] = 200
    data['msg'] = error.getMsg(200)
    return JsonResponse(data)
#
#     # 返回排行榜数据
# def reqBox(request):
#     data = {}
#     data['list'] = []
#     l = models.getBoxTop()
#
#     for i in l:
#         d = {}
#         d.update(i.__dict__)
#         d.pop('_state')
#         d.pop('id')
#         data['list'].append(d)
#
#     data['code'] = 200
#     data['msg'] = error.getMsg(200)
#     return JsonResponse(data)
#
# # 返回词云图
# def resCiyun(request):
#     name = request.GET.get('name')
#     res = ciyun.ciyun(name)
#     code = 200
#     if res == '':
#         code = 2001
#     # 获取评论数据并转化为字典
#     r = models.getComment(name)
#     print(r.__dict__)
#     d ={}
#     d.update(r.__dict__)
#     d.pop('_state')
#     d.pop('id')
#     data = {}
#     data['code'] = code
#     data['msg'] = error.getMsg(code)
#     data['path'] = res
#     data['precent'] = d
#     return JsonResponse(data)
# # 返回类型占比
# def resTypeProportion(request):
#     data = {}
#     types = analysis.getTypes()
#     data['types'] = types
#     data['code'] = 200
#     data['msg'] = error.getMsg(data['code'])
#     return JsonResponse(data)
# # 返回年份数据
# # def resDate(request):
#
# # 返回推荐电影
# def resRecommend(request):
#     res = {}
#     res['code'] = 200
#     line = models.getRandom().content
#     res['msg'] = error.getMsg(200)
#     # if "--" in line:
#     res['line'] = line
#     # else:
#     #     res['line'] = models.getRandom()
#     return JsonResponse(res)
# # 返回历年电影排行
# def resYearTop(request):
#     year = int(request.GET.get('year'))
#     res = {}
#     l = analysis.getCalenderTop(year)
#     res['data'] = l
#     res['code'] = 200
#     res['msg'] = error.getMsg(200)
#     return JsonResponse(res,safe=False)
# # 返回首页推荐
# def resHome(request):
#     res = {}
#     res['code'] = 200
#     res['msg'] = error.getMsg(200)
#     res['data'] = database.getHome()
#     return JsonResponse(res)
# # 返回类型和盈利
# def resTandP(request):
#     res = {}
#     res['code'] = 200
#     res['msg'] = error.getMsg(200)
#     res['data'] = analysis.getTandP(database.getProfit())
#     return JsonResponse(res)
# # 返回类型和评分
# def resTandG(request):
#     res = {}
#     res['code'] = 200
#     res['msg'] = error.getMsg(200)
#     res['data'] = analysis.getTandG(database.getScore())
#     return JsonResponse(res)
# # 返回国家数量
# def resYCount(request):
#     res = {}
#     res['code'] = 200
#     res['msg'] = error.getMsg(200)
#     res['data'] = analysis.countryYear(database.getAll())
#     return HttpResponse(JsonResponse(res))